package org.zjx.action.game;

import org.zjx.action.Action;
import org.zjx.analysis.GameAnalysis;
import org.zjx.core.IWindow;
import org.zjx.entity.Address;

public class GameAction extends Action {
    private GameAnalysis gameAnalysis;

    private void analysis() {
        gameAnalysis = new GameAnalysis(targetWindow, stateManager.getGameState().getScreenshot());
    }

    public GameAction(IWindow targetWindow) {
        super(targetWindow, false);
    }

    @Override
    protected void doExecute() throws Exception {
        analysis();
        Address before = stateManager.getGameState().getAddress();
        Address after = gameAnalysis.getAddress();
        if (before == null || !before.equals(after)) {
            stateManager.getGameState().setAddress(after);
            stateManager.getGameState().setRecordAddressTime(System.currentTimeMillis());
        }
    }
}
